/*
ID: anboia1
LANG: C++
TASK: ride
*/
//...
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
int x, y, i;
char a[7], b[7], d;
int main (){
	freopen("ride.in", "r", stdin);freopen("ride.out", "w", stdout);
	//freopen("in.txt", "r", stdin);
	scanf("%s%s", a, b);
	x=y=1;d='A'-1;
	for(i=0;a[i];++i)x*=(a[i]-d);
	for(i=0;b[i];++i)y*=(b[i]-d);
	//printf("%s: %d\n%s: %d", a, x, b, y);
	if((x%47)==(y%47))printf("GO\n");
	else printf("STAY\n");
	return 0;
}
